# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms_hi.dwd.sqs.dwd_sqs_registration_problem_piece_base_hi import jms_dwd__dwd_sqs_registration_problem_piece_base_hi
from jms_hi.dim.dim_secondary_abnormal_information_base_hi import jms_dim__dim_secondary_abnormal_information_base_hi
from jms_hi.dim.dim_secondary_abnormal_type_base import jms_dim__dim_secondary_abnormal_type_base
from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dwd.dwd_dependent_hi.dwd_dependent_hi_dwd_wide_yl_rt_ssmx_bill_detail_hf import jms_dwd__dwd_dependent_hi_dwd_wide_yl_rt_ssmx_bill_detail_hf
from jms_hi.dm.dm_cainiao_miaomiao_query_detail_dependent_hi import jms_dwd__dm_cainiao_miaomiao_query_detail_dependent_hi
jms_dm__dm_cainiao_miaomiao_query_detail_v2_hi = SparkSqlOperator(
    task_id='jms_dm__dm_cainiao_miaomiao_query_detail_v2_hi',
    task_concurrency=1,
    pool_slots=3,
    master='yarn',
    execution_timeout=timedelta(hours=1),
    depends_on_past=True,
    email=['wangmenglei@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_cainiao_miaomiao_query_detail_v2_hi_{{ execution_date | cst_hour }}',
    sql='jms_hi/dm/dm_cainiao_miaomiao_query_detail_v2_hi/execute.sql',
    driver_memory='4G',
    driver_cores=4,
    executor_cores=4,
    executor_memory='4G',
    num_executors=20,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 25,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '1G',  # 堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict', # 动态分区
        'spark.hadoop.hive.exec.dynamic.partition': 'true',
        'spark.sql.shuffle.partitions': 360
    },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    yarn_queue='pro',
)

jms_dm__dm_cainiao_miaomiao_query_detail_v2_hi << [
    jms_dwd__dwd_sqs_registration_problem_piece_base_hi,
    jms_dim__dim_secondary_abnormal_information_base_hi,
    jms_dim__dim_secondary_abnormal_type_base,
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_dependent_hi_dwd_wide_yl_rt_ssmx_bill_detail_hf,
    jms_dwd__dm_cainiao_miaomiao_query_detail_dependent_hi
]
